﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Bike.Biz;
using Bike.Repository;

namespace Bike.Forms
{
    public partial class Authentication : Telerik.WinControls.UI.RadForm
    {
        public Authentication()
        {
            InitializeComponent();
        }

        private void radButton2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void bntLogin_Click(object sender, EventArgs e)
        {
            //StaffService service = new StaffService();
            //service.Add(new Repository.Staff() {
            //    Password="1", FullName="Truong Nguyen", Roles="Admin;Full", Status="Activating", Username="truong" 
            //});
            string username = txtName.Text.Trim();
            string password = txtPassword.Text;
            if (VerifyAccount(username, password))
            {
                BikeMain main = new BikeMain();
                main.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Sai mật khẩu, vui lòng nhập lại thông tin!", "Đăng nhập sai", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private bool VerifyAccount(string username, string password)
        {
            StaffService service = new StaffService();
            Staff staff = service.GetAuthenticate(username, password);
            if (staff != null)
            {
                SessionManager.CurrentUser = staff;
                return true;
            }
            return false;
        }

        private void txtPassword_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
